package com.example.bms.controller;

import com.example.bms.entity.ApiResult;
import com.example.bms.entity.MultiQuestion;
import com.example.bms.serviceimpl.MultiQuestionServiceImpl;
import com.example.bms.util.ApiResultHandler;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;


/**
 * @apiNote 用于实现对选择题增删改查
 * @author
 * @email 3108289016@qq.com
 * @since 1.0.0
 */
@RestController
@CrossOrigin(origins = "*", methods = {RequestMethod.GET, RequestMethod.POST,RequestMethod.PUT,RequestMethod.DELETE})
public class MultiQuestionController {

    @Autowired
    private MultiQuestionServiceImpl multiQuestionService;


    /**
     * @apiNote 查询选择题题库
     * @author
     * @email 3108289016@qq.com
     * @return ApiResult
     * @since 1.0.0
     */
    @GetMapping("/multiQuestionId")
    public ApiResult findOnlyQuestion() {
        MultiQuestion res = multiQuestionService.findOnlyQuestionId();
        return ApiResultHandler.buildApiResult(200,"查询成功",res);
    }


    /**
     * @apiNote 增加选择题题库试题
     * @param multiQuestion 选择题实体类
     * @author
     * @email 3108289016@qq.com
     * @return ApiResult
     * @since 1.0.0
     */
    @PostMapping("/MultiQuestion")
    public ApiResult add(@RequestBody MultiQuestion multiQuestion) {
        int res = multiQuestionService.add(multiQuestion);
        if (res != 0) {

            return ApiResultHandler.buildApiResult(200,"添加成功",res);
        }
        return ApiResultHandler.buildApiResult(400,"添加失败",res);
    }
}
